<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>药品管理</title>
		<link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../res/css/common/font-awesome.min.css" media="all">
		<link rel="stylesheet" href="../../res/layui-config/css/app.css" media="all">
		<script src="../../res/js/common/session.js"></script>
	</head>
	<body>
		<div class="kit-table">
		    <form class="layui-form" lay-filter="kit-search-form">
				<!-- 左上角的两个按钮 -->
		        <div class="kit-table-header">
		            <div class="kit-search-btns">
		                <a href="javascript:;" data-action="add" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe608;</i> 新增</a>
		                <a href="javascript:;" data-action="del-bulk" class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i> 批量删除</a>
		            </div>
		            <div class="kit-search-inputs">
		                <div class="kit-search-keyword">
		                    <input type="text" class="layui-input" id="serach-one" placeholder="药品.." onKeyUp="lockInput(this,'serach-two')"/>
		                    <button lay-submit lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
		                </div>
		                <div class="kit-search-more" id="kit-search-more">更多筛选<i class="layui-icon">&#xe61a;</i></div>
		            </div>
		        </div>
				<!-- 搜索扩展工具条 -->
		        <div class="kit-search-mored layui-anim layui-anim-upbit">
		            <div class="kit-search-body">
		                <div class="layui-form-item">
		                    <label class="layui-form-label">药品名称</label>
		                    <div class="layui-input-block">
		                        <input type="text" name="drugName" id="serach-two" placeholder="搜索关键字.." autocomplete="off" class="layui-input" onKeyUp="lockInput(this,'serach-one')">
		                    </div>
		                </div>
		                <div class="layui-form-item">
			                <label class="layui-form-label">类型</label>
			                <div class="layui-input-block">
			                    <select name="dtId" id="drug-type">
			                      <option value=""></option>
			                    </select>
			                </div>
		                </div>
		                <div class="layui-form-item">
		                    <div class="layui-inline" style="margin-left: 5px">
		                        <label class="layui-form-label">范围</label>
		                        <div class="layui-input-inline" style="width: 30%;min-width: 60px;">
		                            <input type="text" name="priceMin" placeholder="￥" autocomplete="off" class="layui-input" maxlength="6" onKeyUp="amount(this)">
		                        </div>
		                        <div class="layui-form-mid">-</div>
		                        <div class="layui-input-inline" style="width: 30%;min-width: 60px;">
		                            <input type="text" name="priceMax" placeholder="￥" autocomplete="off" class="layui-input" maxlength="6" onKeyUp="amount(this)">
		                        </div>
		                    </div>
		                </div>
		            </div>
		            <div class="kit-search-footer">
		                <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary kit-btn reset-btn">重置</button>
		                <button lay-submit lay-filter="search" class="layui-btn layui-btn-sm kit-btn">确定</button>
		            </div>
		        </div>
		    </form>
				
			<!-- 操作按钮 -->
		    <div class="kit-table-body">
		        <table id="demo" lay-filter="demo"></table>
		        <script type="text/html" id="views">
					<button class="layui-btn layui-btn-xs" lay-event="specification">说明书</button>
		            <button class="layui-btn layui-btn-xs" lay-event="detail">物料清单</button>
					<button class="layui-btn layui-btn-xs" lay-event="auditDetail">审核明细</button>
				</script>
		        <script type="text/html" id="tools">
					<button class="layui-btn layui-btn-xs" lay-event="check">提交审核</button>
		            <button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>
		            <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
		        </script>
		    </div>
		</div>
		<!-- 药品修改页面 -->
		<script type="text/html" id="drug-edit-tpl">
		    <div style="margin:10px">
		        <form class="layui-form" action="" lay-filter="form-edit">
		            <input type="hidden" name="drugId" value="{{d.rowdata.drugId}}" />
					<input type="hidden" name="audId" value="{{d.rowdata.audId}}" />
					<input type="hidden" name="audState" value="{{d.rowdata.audState}}" />
					<input type="hidden" name="drugPictrue" value="{{d.rowdata.drugPictrue}}" >
		            <div class="layui-form-item">
		                <label class="layui-form-label">名称</label>
		                <div class="layui-input-block">
		                    <input type="text" name="drugName" required lay-verify="required" value="{{d.rowdata.drugName}}" placeholder="请输入名称" autocomplete="off" class="layui-input">
		                </div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">类型</label>
		                <div class="layui-input-block">
		                    <select name="dtId" required lay-verify="required">
		                      <option value="请选择类型"></option>
		                      {{# layui.each(d.types,function(index,item){ }}                      
		                      {{# if(item.dtId===d.rowdata.dtId){}}
		                      <option value="{{item.dtId}}" selected>{{item.dtName}}</option>
		                      {{#}else{}}
		                      <option value="{{item.dtId}}">{{item.dtName}}</option>
		                      {{#};}}
		                      {{# }); }}
		                    </select>
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">单位</label>
		                <div class="layui-input-block">
		                    <input type="text" name="drugUnit" required lay-verify="required" value="{{d.rowdata.drugUnit}}" placeholder="请输入单位" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">属性</label>
		                <div class="layui-input-block">
		                    {{# var otc = d.rowdata.drugProp === '0'?'checked':'';}} {{# var rx = d.rowdata.drugProp === '1'?'checked':'';}}
		                    <input type="radio" name="drugProp" value="1" title="处方药" {{rx}} />
		                    <input type="radio" name="drugProp" value="0" title="非处方药" {{otc}} />
		                </div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">价格</label>
		                <div class="layui-input-block">
		                    <input type="text" name="drugPrice" required lay-verify="required" maxlength="6" value="{{d.rowdata.drugPrice}}" placeholder="请输入金额" autocomplete="off" class="layui-input activity_card_money" onKeyUp="amount(this)">
		                </div>
		            </div>
					<div class="layui-form-item layui-upload ">
  		  				<label class="layui-form-label">图片</label>
						<div class="layui-upload layui-input-block">
		  					<button type="button" class="layui-btn layui-btn-primary" id="fileBtn"><i class="layui-icon">&#xe67c;</i>{{d.rowdata.msg}}</button>
		  					<div class="layui-upload-list" style="display: none">
		    					<img class="layui-upload-img" id="pic" src="../../{{d.rowdata.drugPictrue}}" style="width: 100px;height: 100px">
		    					<p id="errorText"></p>
		  					</div>
						</div>
					</div>
		            <div class="layui-form-item" style="display:none;">
		                <div class="layui-input-block">
		                    <button class="layui-btn" lay-submit lay-filter="formEdit1">立即提交</button>
		                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		                </div>
		            </div>
		        </form>
		    </div>
		</script>
		<!-- 说明书修改页面 -->
		<script type="text/html" id="spe-edit-tpl">
		    <div style="margin:10px">
		        <form class="layui-form" action="" lay-filter="form-edit">
		            <input type="hidden" name="drugId" value="{{d.rowdata.drugId}}" />
					<input type="hidden" name="specId" value="{{d.rowdata.specId}}" />
					<input type="hidden" name="audId" value="{{d.rowdata.audId}}" />
					<input type="hidden" name="audState" value="{{d.rowdata.audState}}" />
		            <div class="layui-form-item">
		                <label class="layui-form-label">药品名称</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specName" required lay-verify="required" value="{{d.rowdata.specName}}" placeholder="请输入名称" autocomplete="off" class="layui-input">
		                </div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">性状</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specTrait" required lay-verify="required" value="{{d.rowdata.specTrait}}" placeholder="请输入性状" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">功能主治</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specPurpose" required lay-verify="required" value="{{d.rowdata.specPurpose}}" placeholder="请输入功能主治" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">规格</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specSize" required lay-verify="required" value="{{d.rowdata.specSize}}" placeholder="请输入规格" autocomplete="off" class="layui-input">
		                </div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">用法用量</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specUse" required lay-verify="required" value="{{d.rowdata.specUse}}" placeholder="请输入用法用量" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">不良反应</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specEffect" required lay-verify="required" value="{{d.rowdata.specEffect}}" placeholder="请输入不良反应" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">禁忌</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specTaboo" required lay-verify="required" value="{{d.rowdata.specTaboo}}" placeholder="请输入禁忌" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">注意事项</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specNotice" required lay-verify="required" value="{{d.rowdata.specNotice}}" placeholder="请输入注意事项" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">药物相互作用</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specInteract" required lay-verify="required" value="{{d.rowdata.specInteract}}" placeholder="请输入药物相互作用" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">贮藏</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specDepot" required lay-verify="required" value="{{d.rowdata.specDepot}}" placeholder="请输入贮藏" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">包装</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specPack" required lay-verify="required" value="{{d.rowdata.specPack}}" placeholder="请输入包装" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">有效期</label>
		                <div class="layui-input-block">
		                    <input type="text" name="specValidity" required lay-verify="required" value="{{d.rowdata.specValidity}}" placeholder="请输入有效期" autocomplete="off" class="layui-input">
		                </div>
		            </div>
					
		            <div class="layui-form-item" style="display:none;">
		                <div class="layui-input-block">
		                    <button class="layui-btn" lay-submit lay-filter="formEdit2">立即提交</button>
		                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		                </div>
		            </div>
		        </form>
		    </div>
		</script>
		<script src="../../res/js/common/jquery-1.11.2.min.js"></script>
		<script>
			//文本框只能输入金额
		    function amount(th){
		        var regStrs = [
		            ['^0(\\d+)$', '$1'], //禁止录入整数部分两位以上，但首位为0
		            ['[^\\d\\.]+$', ''], //禁止录入任何非数字和点
		            ['\\.(\\d?)\\.+', '.$1'], //禁止录入两个以上的点
		            ['^(\\d+\\.\\d{2}).+', '$1'] //禁止录入小数点后两位以上
		        ];
		        for(i=0; i<regStrs.length; i++){
		            var reg = new RegExp(regStrs[i][0]);
		            th.value = th.value.replace(reg, regStrs[i][1]);
		        }
		    }
			//搜索框同步输入
			function lockInput(obj,id){
				$("#"+id).val($(obj).val());
			}
		</script>
		<script src="../../res/layui/layui.all.js"></script>
		<script type="text/html" id="img">
			<img style="height:100%;height:30px;" onclick="getPathOver(this)" src="../../{{ d.drugPictrue}}">
		</script>
		<script>
			//弹出层下标
			var layerIndex1,layerIndex2,layerIndex3,editIndex1,editIndex2,editIndex3;
			//显示表格数据
		    layui.use(['table','upload'], function() {
		    	var admin = getSession("../../");
		        var table = layui.table,
		            $ = layui.jquery,
		            layer = layui.layer,
		            form = layui.form,
		            laytpl = layui.laytpl;
		    	var tableIns = table.render({
		            elem: '#demo',
		            height: 'full-50', //容器高度
		            url: '../../drug/showList.action',
		            where: {"comId": admin.comId},
		            page: true,
		            id: 'demo',
		            cols: [
		                [{checkbox: true,fixed: true},
		                {field: 'drugId',title: 'ID',width: 120},
		                {field: 'drugName',title: '药名',minWidth: 120},
		                {field: 'drugUnit',title: '单位',width: 60},
		                {field: 'dtName',title: '类型',width: 90},
		                {field: 'drugProp',title: '属性',width: 90},
		                {field: 'drugPictrue',title: '图片',width: 60,templet:'#img'},
		                {field: 'drugPrice',title: '价格（元）',width: 120,sort: true},
		                {field: 'audState',title: '审核状态',width: 140},
		                {fixed: 'right',title: '查看',width: 228,align: 'center',toolbar: '#views'},
		                {fixed: 'right',title: '操作',width: 205,align: 'center',toolbar: '#tools'}]
		            ],
		            done: function(res, curr, count) {
		            	var tableElem = this.elem.next('.layui-table-view');
		                $("[data-field = 'drugProp']").children().each(function(){
						    if($(this).text() == '1'){
						    	$(this).text("处方药");
						    } else if ($(this).text() == '0') {
						    	$(this).text("非处方药");
						    }
					  	});
		                $("[data-field = 'drugPictrue']").children().each(function(){
		                	var obj = $(this);
		                	obj.find('img').on("error", function () {
		                		obj.text('无');
		                	});
		                	obj.find('img').on("load", function () {
		                		obj.find('img').mouseover(function() {
			                		layer.tips("点击查看", this, {
		                            	tips: [3, "#4794ec"],time: 1000
		                          	});
		                      	});
		                	});
					  	});
		                $("[data-field = 'audState']").children().not(":first").each(function(index){
		                	var id = $(this).parents('tr').find('td[data-field="drugId"]').text();
		                	var o = $(this);
	            			if (o.text() == '10101') {
	            				o.html('<font style="color: #0000F0">等待经理审核</font>');
	            				tableElem.find('tr[data-index="' + index + '"]').find('button').addClass('layui-btn-disabled').attr('disabled',true);
	            			} else if (o.text() == '10110') {
	            				o.html('<font style="color: #F00000">不通过</font>');
	            			} else if (o.text() == '10111') {
	            				o.html('<font style="color: #00F000">通过</font>');
	            				tableElem.find('tr[data-index="' + index + '"]').find('button[lay-event="check"]').addClass('layui-btn-disabled').attr('disabled',true);
	            			} else if (o.text() == '-1' || o.text() == '10112' || o.text() == '10113') {
	            				o.text("未审核");
	            				tableElem.find('tr[data-index="' + index + '"]').find('button[lay-event="auditDetail"]').addClass('layui-btn-disabled').attr('disabled',true);
	            			}
					  	});
		                renderForm();
		            }
		        });
		        
				//查询类型下拉框数据
		        var staticData = null;
		        $.ajax({ 
		        	url:"../../drugType/showList.action",
                    type:'post',//method请求方式，get或者post
                    async:false,//同步
                    dataType:'json',//预期服务器返回的数据类型
                    success:function(mes){//res为相应体,function为回调函数
                    	//增加及修改类型下拉框内的数据
                    	staticData = mes;
                    	//循环添加类型搜索框内的数据
                    	$.each(mes.types,function(index,item){
                    		$("#drug-type").append("<option value="+item.dtId+">"+item.dtName+"</option>");
                    	});
                    	//渲染类型搜索框内的下拉框
                    	renderForm();
                    }
                 });
		        
		      	//点击排序重新渲染表格
		        table.on('sort(demo)', function(obj){
		        	tableIns.reload();
		        });
		        
		        //监听搜索表单提交
		        form.on('submit(search)', function(data) {  
		            //带条件查询
		            tableIns.reload({
		                where: data.field,
		                page: { curr: 1 }
		            });
		            $('.kit-search-mored').hide();//关闭搜索层
		            return false;
		        });
		        
		        //监听工具条按钮点击
		        table.on('tool(demo)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
		            var data = obj.data; //获得当前行数据
		            var layEvent = obj.event; //获得 lay-event 对应的值
		            var tr = obj.tr; //获得当前行 tr 的DOM对象
		
		            if (layEvent === 'detail') { //物料清单
		            	layer1(data.drugId,data.audId,data.drugName,data.audState);
		            } else if (layEvent === 'specification') { //说明书
		            	layer2(data.drugId,data.audId,data.drugName,data.audState);
		            } else if (layEvent === 'auditDetail') { //审核明细
		            	layer3(data.drugId,"0","总经理审核");
		            } else if (layEvent === 'check') { //提交审核
		            	$.ajax({ 
		            		url:"../../drug/check.action",
		            		data:{"comId": admin.comId,"drugId":data.drugId},
		                    type:'post',//method请求方式，get或者post
		                    async:false,//同步
		                    dataType:'json',//预期服务器返回的数据类型
		                    success:function(mes){//res为相应体,function为回调函数
		                    	layer.msg(mes.msg);
		                    	if (mes.status==1) tableIns.reload();
		                    }
		                 });
		            } else if (layEvent === 'del') { //删除
		                layer.confirm('真的删除行么', function(index) {
		                	layer.close(index);
		                    update("../../drug/addDrug.action",{"drugId":data.drugId,"isva":"0"});
		                });
		            } else if (layEvent === 'edit') { //编辑
		            	data["msg"]="更改图片";
		                var d = {
		                	rowdata: data,
		                    types: staticData.types
		                };
		                editLayer1(d);
	            		$(".layui-upload-list").css("display", "block");
		            }
		        });
		        
		        //表单渲染
		        form.render(null, 'kit-search-form');
		        //更多筛选点击事件
		        $('#kit-search-more').on('click', function() {
		            $('.kit-search-mored').toggle();
		        });
		        
		        //药品增加和修改弹出层   提交按钮点击事件
		        
		        form.on('submit(formEdit1)', function(data) {
                	if ($("input[name=drugPictrue]").val()=="") {
                		layer.msg('未上传文件');
                    	$("#fileBtn").html('<span style="color:red"><i class="layui-icon">&#xe67c;</i>选择图片</span>');
                    	form.render(null, 'form-edit');
                    	return false;
                    }
                	data.field["comId"]=admin.comId;
                	var cls = update("../../drug/addDrug.action",data.field);
                	if (cls) editIndex1 && layer.close(editIndex1); //关闭弹出层
                	return false;
		        });
		        
		      	//说明书增加和修改弹出层   提交按钮点击事件
		        form.on('submit(formEdit2)', function(data) {
		        	var cls = update("../../spec/addOrUpdate.action",data.field);
                	if (cls) editIndex2 && layer.close(editIndex2); //关闭弹出层
                	layerIFrameReload(layerIndex2);
                	return false;
		        });
		        
		        //增加、批量删除 按钮点击事件
		        $('.kit-search-btns').children('a').off('click').on('click', function() {
		            var $that = $(this),
		                action = $that.data('action');
		            switch (action) {
		            	//点击的是 增加按钮
		                case 'add':
		                    var d = {
		                		//替换增加页面文本框内出现的undefine
		                        rowdata: {
		                        	drugId: '',drugName: '',drugProp: 1,drugUnit: '',drugPrice: '',drugPictrue: '',drugProp: '0',msg: '选择图片'
		                        },
		                        //类型下拉框数据
		                        types: staticData.types
		                    };
		                    editLayer1(d);
		                    break;
		                    
		                //点击的是 批量删除按钮
		                case 'del-bulk':
		                    var d = table.checkStatus('demo');
		                    if (d.data.length === 0) {
		                        layer.msg('请选择要删除的数据');
		                        return;
		                    }
		                    var data = d.data,
		                        names = [],
		                        ids = [];
		                    layui.each(data, function(index, item) {
		                        names.push(item.drugName);
		                        ids.push(item.drugId);
		                    });
		                    layer.confirm('真的删除行么', function(index) {
		                    	layer.close(index);
		                    	update("../../drug/bulkUpdate.action",ids);
			                });
		                    break;
		            }
		        });
		    });
			
		  	//显示 物料清单
			function layer1(id,id2,name,state){
				layerIndex1 = layer.open({
				  type: 2,
				  title: '药品配置',
				  content: '../materialList/index.html?id='+id+'&id2='+id2+'&name='+name+'&state='+state,
				  area: ['100%', '100%'],
				  maxmin: false
				});
				layer.full(layerIndex1);
			}
		  	
		  	//显示 说明书
			function layer2(id,id2,name,state){
				layerIndex2 = layer.open({
				  type: 2,
				  title: '说明书',
				  content: '../specification/specification.html?id='+id+'&name='+name,
				  area: ['800px', '430px'],
				  maxmin: true,
				  success: function (layero, index)
                  {
                      var body = layer.getChildFrame('body', index);
                      var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                      body.find("#btn,#btn-err").on("click",function(){
                    	  showUpdate(id,id2,state);
                      });
                  }
				});
		  	}
		  	
		  	//显示 审核明细
			function layer3(id,type,name){
				layerIndex3 = layer.open({
				  type: 2,
				  title: '审核明细',
				  content: '../audit/detail/drugDetail.html?id='+id+'&type='+type+'&name='+name,
				  area: ['800px', '430px'],
				  maxmin: true
				});
		  	}
		  	
		  	//渲染 药品修改和增加弹出层
		    function editLayer1(d){
	    		layui.laytpl($('#drug-edit-tpl').html()).render(d,function(html) {
	    			editIndex1 = layer.open({
                        type: 1,
                        title: '药品操作',
                        content: html,
                        maxmin: true,
                        area: ['800px', '430px'],
                        btn: ['提交', '重置', '取消'],
                        yes: function(index, layero) {
                            $('form[lay-filter="form-edit"]').find('button[lay-submit]').click();
                        },
                        btn2: function(index, layero) {
                            $('form[lay-filter="form-edit"]').find('button[type="reset"]').click();
                            return false;
                        },
                        success: function() {
                            layui.form.render(null, 'form-edit');
                        }
                    });
                    uploads();
                });
	    		return 
		    }
		  	
		  	//渲染 说明书修改和增加弹出层
		    function editLayer2(d){
	    		layui.laytpl($('#spe-edit-tpl').html()).render(d,function(html) {
	    			editIndex2 = layer.open({
                        type: 1,
                        title: '说明书编辑',
                        content: html,
                        maxmin: true,
                        area: ['800px', '430px'],
                        btn: ['提交', '重置', '取消'],
                        yes: function(index, layero) {
                            $('form[lay-filter="form-edit"]').find('button[lay-submit]').click();
                        },
                        btn2: function(index, layero) {
                            $('form[lay-filter="form-edit"]').find('button[type="reset"]').click();
                            return false;
                        },
                        success: function() {
                        	layui.form.render(null, 'form-edit');
                        }
                    });
                });
		    }
		  	
		  	//说明书增加修改页面上屏
	        function showUpdate(id,id2,state){
		  		$.ajax({ 
          		  url:"../../spec/findById.action",
          		  data:{"drugId":id},
                    type:'post',//method请求方式，get或者post
                    async:false,//同步
                    dataType:'json',//预期服务器返回的数据类型
                    success:function(mes){//res为相应体,function为回调函数
                  	  if (mes.data==null) {
                  		  var d = {
              				rowdata: {
              					specId: '', drugId: id, specName: '',specTrait: '',specPurpose: '',specSize: '',specUse: '',specEffect: '',specTaboo: '',specNotice: '',specInteract: '',specDepot: '',specPack: '',specValidity: '',audId: id2,audState: state
		                        }
						      }; 
                  	  } else {
                  		  mes.data["audId"]=id2;
                  		  mes.data["audState"]=state;
                  		  var d = {
							rowdata: mes.data
						  };
                  	  }
					  editLayer2(d);
					  //渲染类型搜索框内的下拉框
					  renderForm();
                    }
                });
		  	}
		  	
		    //药品增加、修改、删除、批量删除 都是用的这一个方法
		    function update(url,data){
		    	var cls = false;
		    	$.ajax({
		    		url: url,
                    type:'post',//method请求方式，get或者post
                    async:false,//同步
                    dataType:'json',//预期服务器返回的数据类型
                    data: JSON.stringify(data),//表格数据序列化
                    contentType: "application/json; charset=utf-8",
                    success:function(mes){//res为相应体,function为回调函数
                        if(mes.status==1){ 
                        	cls = true;//有弹出层时是关闭弹出层 false不关闭
	                        $("#res").click();//调用重置按钮将表单数据清空
	                        $(".layui-laypage-btn")[0].click();//当前表格刷新
                        }
                        layer.msg(mes.msg);
                    },
                   	error:function(){layer.alert('数据异常，请稍后重试！！！',{icon:5});}
                 });
		    	return cls;
		    }
		    
		    //上传文件
		    function uploads(){
		    	//普通图片上传
		        var uploadInst = layui.upload.render({
		          elem: '#fileBtn'
		          ,url: '../../drug/upload.action'
		          ,before: function(obj){
		            //预读本地文件示例，不支持ie8
		            obj.preview(function(index, file, result){
		            	$(".layui-upload-list").css("display", "block");
		                $('#pic').attr('src', result); //图片链接（base64）
		            });
		          }
		          ,done: function(res){
		            //如果上传失败
		            if(res.code > 0){
		              return layer.msg('上传失败');
		            }
		            //上传成功
		            $("input[name=drugPictrue]").val(res.obj);
		            $(".layui-upload-list").css("display", "block");
	           		$("#fileBtn").html('<i class="layui-icon">&#xe67c;</i>更改图片');
	           		layui.form.render('form-edit');
		          }
		          ,error: function(){
		            //演示失败状态，并实现重传
		            var demoText = $('#errorText');
		            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
		            demoText.find('.demo-reload').on('click', function(){
		              uploadInst.upload();
		            });
		          }
		        });
		    }
		    //刷新弹出层
		    function layerIFrameReload(layerIndex) {
	    	  window['layui-layer-iframe' + layerIndex].location.reload();
	    	}
		    
		  	//重新渲染表单
		  	function renderForm(){ 
	  			layui.use('form', function(){ 
		  			var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加() 
		  			form.render(); 
	  			}); 
	  		}
		  	
		  	/**
			*鼠标进入时
			*/
			function getPathOver(obj){
				$("body").append('<div id="layer"></div><img id="pic" src="#" style="width:280px;height:280px;display:none;z-index:99;border-radius: 2px;margin: auto;position: absolute;top: 0px;bottom: 0px;left: 0px;right: 0px;border: 1px solid #424242"/>');
				$("#layer").addClass("layer").fadeIn("slow");
				$("#layer").click(function(){
					getPathOut();
				});
				$("#pic").fadeIn("slow");
				$('#pic').attr({"src":obj.src});
			}
			/**
			*鼠标退出时
			*/
			function getPathOut(){
				$("#layer").fadeOut("slow");
				$("#pic").fadeOut("slow");
			}
			
		    //ajax加载动画
		    $(function () {
	            $.ajaxSetup({
	                layerIndex:-1,
	                beforeSend: function () {
	                    this.layerIndex = layer.load(1, { shade: [0.8, '#ffffff'] });
	                },
	                complete: function () {
	                    layer.close(this.layerIndex);
	                },
	                error: function () {
	                    layer.alert('部分数据加载失败，可能会导致页面显示异常，请刷新后重试', {
	                        skin: 'layui-layer-molv'
	                       , closeBtn: 0
	                       , shift: 4 //动画类型
	                    });
	                }
	            });
	        });
		</script>
	</body>
</html>
